const fs = require("fs");
const path = require("path");

//  /   /home
function home(response, param) {
  response.writeHeader(200, { "Content-Type": "text/html" });
  fs.createReadStream(path.resolve(__dirname, "html/home.html")).pipe(response);
}

// /user
function user(response, param) {
  response.writeHeader(200, { "Content-Type": "application/json" });
  // response.end(JSON.stringify());
  fs.createReadStream(path.resolve(__dirname, "json/user.json")).pipe(response);
}

// list
function list(response, param) {
  response.writeHeader(200, { "Content-Type": "application/json" });
  // response.end(JSON.stringify([
  //   { name: "小七2", age: 12 },
  //   { name: "小七3", age: 12 },
  // ]))
  response.end(JSON.stringify(param))
}

module.exports = {
  home,
  user,
  list,
}